#include "MessageTest.h"

#include "../protocol/message.h"
#include <QByteArray>

using namespace Opl::Protocol;

void MessageTest::createMessage()
{

	QByteArray ba;
	QDataStream stream(&ba, QIODevice::ReadWrite);
	Message msg = Message::createCommand("test_command");
	stream << msg;

	QDataStream stream2(ba);
	Message msg2;
	stream2 >> msg2;

	QCOMPARE(msg2.hdr.Size(), msg.hdr.Size());
	QCOMPARE(msg2.hdr.Type(), msg.hdr.Type());

	QCOMPARE(msg2.id, msg.id);
	QCOMPARE(msg2.data, msg.data);

	

}

void MessageTest::fromByteArrayMessage()
{

	QByteArray ba;
	QDataStream stream(&ba, QIODevice::ReadWrite);
	Message msg = Message::createCommand("test_some command \0 \t wit%h some \0\n\n\n special chars\r\t\0");
	stream << msg;

	Message msg3(ba);
	QCOMPARE(msg3.hdr.Size(), msg.hdr.Size());
	QCOMPARE(msg3.hdr.Type(), msg.hdr.Type());

	QCOMPARE(msg3.id, msg.id);
	QCOMPARE(msg3.data, msg.data);

}